%% Author: Administrator
%% Created: 2009-3-20
%% Description: TODO: Add description to store_test
-module(store_test).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([get/1,put/2]).

%%
%% API Functions
%%
get(Key) ->
    {ok, Socket} = gen_tcp:connect("10.0.0.253", 8899, [binary, {packet, 4}]),
    ok = gen_tcp:send(Socket, term_to_binary({get, Key})),
    receive
        {tcp, Socket, Bin} ->
            Res = binary_to_term(Bin),
%            io:format("Stroe value: ~p~n", [Res]),
            Res;
        {tcp_closed, Socket} ->
            io:format("end socket~n"),
            {error, tcp_closed}
    end.

put(Key, Value) ->
    {ok, Socket} = gen_tcp:connect("10.0.0.253", 8899, [binary, {packet, 4}]),
    ok = gen_tcp:send(Socket, term_to_binary({put, Key, Value})),
    receive
        {tcp, Socket, Bin} ->
            io:format("Store return: ~p~n", [binary_to_term(Bin)]);
        {tcp_closed, Socket} ->
            log4erl:info("Stored~n")
    end.

%%
%% Local Functions
%%

